package com.zhouyu.service;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.*;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.context.event.EventListener;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Priority;

@Priority(1)
@Component("user1")
public class User implements InitializingBean ,Phased , ApplicationContextAware , DisposableBean , SmartLifecycle, BeanNameAware,SmartInitializingSingleton {



	public String userName;



 	private ApplicationContext applicationContext;

	public User(){
		System.out.println("User的构造器-----------");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("InitializingBean-----afterPropertiesSet"  );
	}
	public void initMethod(){
		System.out.println("BeanDefinition-----initMethod");
	}




	@Override
	public void destroy() throws Exception {
		System.out.println("DisposableBean---destroy"  );
	}



	public void destoryMethod(){
		System.out.println("BeanDefinition----destoryMethod");

	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		System.out.println("ApplicationContext------applicationContext"  );
	}

	public ApplicationContext getApplicationContext() {
		return applicationContext;
	}

	@Override
	public void start() {
		System.out.println("Lifecycle----------start");
	}

	@Override
	public void stop() {
		System.out.println("Lifecycle----------stop");

	}

	@Override
	public boolean isRunning() {
		System.out.println("Lifecycle----------isRunning");
		return false;
	}


	@Override
	public void setBeanName(String name) {
		System.out.println("BeanNameAware----------setBeanName");
		this.userName = name;
	}

	@PostConstruct
	public void testPostConstruct(){
		System.out.println("InitDestoryAnnotationBeanPostProcessor-------PostConstruct");
	}


	@PreDestroy
	public void testPreDestroy(){
		System.out.println("InitDestoryAnnotationBeanPostProcessor-------PreDestroy");
	}

	@Override
	public int getPhase() {
		return 1;
	}


	@Override
	public void afterSingletonsInstantiated() {
		System.out.println("SmartInitializingSingleton-------afterSingletonsInstantiated");

	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
}
